package com.albertzhe.util02;

import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;

import java.io.IOException;
import java.io.InputStream;
import java.util.Properties;


public class JdbcUtilsDao {

    @Data
    @Builder
    @NoArgsConstructor
    @AllArgsConstructor
    private class DBProduct {
        private String username;
        private String password;
        private String driver;
        private String url;
    }


    /**
     * 读取配置文件
     */
    public void readProperty() throws IOException {
        InputStream in = this.getClass().getClassLoader().getResourceAsStream("db.properties");
        Properties prop = new Properties();
        prop.load(in);

        DBProduct product = DBProduct.builder()
                .username(prop.getProperty("jdbc.username"))
                .password(prop.getProperty("jdbc.password"))
                .driver(prop.getProperty("jdbc.driver"))
                .url(prop.getProperty("jdbc.url"))
                .build();
        System.out.println(product);
    }


    ///**
    // * 获得数据库的连接
    // */
    //public Connection getConnection() throws SQLException {
    //    ComboPooledDataSource cpds = new ComboPooledDataSource();
    //    Connection connection = cpds.getConnection();
    //    return connection;
    //}

}

